<?php

namespace app\store\controller\shops;

use app\store\controller\BaseController;
use app\store\service\OfflineShopService;
use app\store\service\UserService;
use think\facade\View;

class StoresController extends BaseController
{
    public function index()
    {   

        $param = $this->request->param();

        $storeUserService = new OfflineShopService();
        $list = $storeUserService->auditList($param);
        // print_r($list);exit;
        return View::fetch('',['list' => $list]);
    }

    public function list()
    {   

        $param = $this->request->param();

        $storeUserService = new OfflineShopService();
        $list = $storeUserService->shopList($param);
        // print_r($list);exit;
        return View::fetch('',['list' => $list]);
    }

    // public function option()
    // {
    //     $param = $this->request->param();

    //     $storeUserService = new UserService();
    //     $list = $storeUserService->getUserList($param);

    //     View::engine()->layout(false);

    //     return View::fetch('',['list' => $list]);
    // }

    /**
     * 更新店铺状态
     */
    public function setStatus()
    {
        $param = $this->request->post();
        $rst = OfflineShopService::updateStatus($param);
        if ($rst) {
            return json(['code' => 1, 'msg' => '更新成功!']);
        } else {
            return json(['code' => 0, 'msg' => '更新失败!']);
        }
    }


    /**
     * 更新推荐店铺
     */
    public function switch()
    {
        $param = $this->request->post();
        $rst = OfflineShopService::updateTJ($param);
        if ($rst) {
            return json(['code' => 1, 'msg' => '更新成功!']);
        } else {
            return json(['code' => 0, 'msg' => '更新失败!']);
        }
    }

    public function editHs()
    {
        $id = $this->request->param('id/d');
        $StoreUserService = new OfflineShopService();
        $row = $StoreUserService->findSHOne($id);
        // print_r($row['bg_img']);
        return View::fetch('edit',['row' => $row]);
    }

    public function edit()
    {
        $id = $this->request->param('id/d');
        $StoreUserService = new OfflineShopService();
        $row = $StoreUserService->findOne($id);
        // print_r($row['bg_img']);
        return View::fetch('',['row' => $row]);
    }

    public function update()
    {
        $param = $this->request->param();
        $id = $this->request->param('id/d');
        $StoreUserService = new OfflineShopService();
        $row = $StoreUserService->findOne($id);
        if(empty($row) ) {
            return json(['code' => 0, 'msg' => '未找到指定内容!']);
        }
        if ($row['status'] !=1) {
            return json(['code' => 0, 'msg' => '未找到指定内容!']);
        }
        if (isset($param['status']) && $param['status']) {
            $rst = $StoreUserService->auditShop($param['status'], $id, $row['uid']);
            if (!$rst) {
                return json(['code' => 0, 'msg' => '审核失败!']);
            }
        }
        return json(['code' => 1, 'msg' => '操作成功!']);
    }


    
}